package com.ruoyi.web.controller.tool;

import com.ruoyi.SpringContextUtil;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.StringUtils;
import groovy.lang.Binding;
import groovy.lang.GroovyShell;
import groovy.lang.Script;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.*;

/**
 * swagger 用户测试方法
 * 
 * @author ruoyi
 */
//@Api("用户信息管理2")
@RestController
@RequestMapping("/test1/groovy")
public class TestController2 extends BaseController
{

    @Resource
    private GroovyClassLoaderRule groovyClassLoaderRule;


//    @ApiOperation("调用javabean方法")
//    @ApiImplicitParam(name = "userId", value = "用户ID", required = true, dataType = "int", paramType = "path", dataTypeClass = Integer.class)
    @RequestMapping("/usebean")
    public String groovyInvokeJavaMethodTest() {
        GroovyShell groovyShell = new GroovyShell();
        Script script = groovyShell.parse("package groovy\n" +
                "\n" +
                "import com.ruoyi.web.controller.tool.GroovyInvokeJavaDemo\n" +
                "import com.ruoyi.system.service.ISysUserService\n" +
                "import com.ruoyi.SpringContextUtil\n" +
                "\n" +
                "/**\n" +
                " * 静态变量\n" +
                " */\n" +
                "class Globals {\n" +
                "    static String PARAM1 = \"静态变量\"\n" +
                "    static int[] arrayList = [1, 2]\n" +
                "}\n" +
                "\n" +
                "def getBean() {\n" +
                "    ISysUserService userService = SpringContextUtil.getBean(ISysUserService.class);\n" +
                "    return userService.selectUserList()\n" +
                "}");
        //执行
        List<SysUser> userList = (List<SysUser>)script.invokeMethod("getBean", null);
        return userList.toString();

    }

}



